package com.example.demo01.Service;

import com.example.demo01.Entity.SalesOpportunity;
import com.example.demo01.Repository.SalesOpportunityRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class SalesOpportunityService {

    @Autowired
    private SalesOpportunityRepository opportunityRepository;

    public SalesOpportunity createOpportunity(SalesOpportunity opportunity) {
        return opportunityRepository.save(opportunity);
    }

    public List<SalesOpportunity> getAllOpportunities() {
        return opportunityRepository.findAll();
    }
    // 根据 ID 获取销售机会
    public SalesOpportunity getOpportunityById(Long id) {
        Optional<SalesOpportunity> opportunity = opportunityRepository.findById(id);
        return opportunity.orElse(null);  // 如果找不到，返回 null
    }


}
